// $codepro.audit.disable declareAsInterface
/**
 * Patient class
 */
package edu.gatech.userclasses;

import java.util.ArrayList;
import java.util.Collection;

import javax.swing.JOptionPane;

import edu.gatech.datastorage.Gender;
import edu.gatech.datastorage.PatientInformation;
import edu.gatech.datastorage.TreatmentRecord;
import edu.gatech.utilities.Persistence;


/**
 * Patient class with the abilty to login and create/view appointments.
 * @author Dan Holdridge
 * @version 1.p
 *
 */
public class Patient extends User {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3706377919927847448L;

	/**
	 * Stores the PatientInformation object for the Patient
	 */
	private PatientInformation info;
	
	/**
	 * Creates a Patient object by taking in PatientInformation
	 * @param info PatientInformation object with the all of the Patient's
	 * medical information
	 */
	public Patient(PatientInformation info) {
		this.info = info;
		this.name = info.getName();
		this.username = info.getName();
		this.password = info.getPassword();
		this.userType = "Patient";
	}

	/**
	 * 
	 * @param username
	 * @param password
	 */
	public Patient(String username, String password){
		this.username = username;
		this.password = password;
		this.name = username;
		final ArrayList<String> meds = new ArrayList<String>();
		meds.add("Medications");
		final ArrayList<String> allergies = new ArrayList<String>();
		meds.add("Allergies");
		final PatientInformation info = new PatientInformation(name, "Password", 0,
				Gender.MALE, "Phone Number", "Address", "Pharmacy", 
				"Insurance", meds, allergies, "Date of Birth");
		this.info = info;
		this.userType = "Patient";
	}
	
	/**
	 * Creates a Patient using only a name
	 * @param name The name of the Patient
	 */
	public Patient(String name) {
		this.name = name;
		this.userType = "Patient";
	}
	
	/**
	 * Default constructor
	 */
	public Patient() {
		this("John Doe");
	}
	
	/**
	 * Creates a new appointment and adds it to the appointment list in
	 * the patient's PatiendInformation record.
	 * 
	 * @param reason The reason for the visit
	 * @param time The time of visit
	 * @param date The day of the visit
	 * @param desiredDoc The name of the doctor the patient wishes to see
	 */
	public void makeAppointment(String reason, String time, String date,
			String desiredDoc) {
		info.getHistory().add( new TreatmentRecord(reason, time, date, desiredDoc) );
	}
	
	/**
	 * Retirieves all of the appointments for the patient, past and future.
	 * @return A list of appointments from PatientInfo
	 *///TODO Well, a lot really... what do we want to do with this list of appointments?
	public Collection<String> viewAppointments() {
		final Collection<TreatmentRecord> list = info.getHistory();
		final Collection<String> appointments = new ArrayList<String>(list.size() );
		for (TreatmentRecord record : list) {
			appointments.add( record.getAppointment().toString() );
		}
		return appointments;
	}

	/**
	 * @return the info
	 */
	public PatientInformation getInfo() {
		return info;
	}
	
	/**
	 * Edits the patient by changing its PatientInformation
	 * @param info
	 */
	public void editPatient(PatientInformation info){
		this.setInfo(info);
		this.setName(name);
		this.setPassword(password);
		Persistence.refresh();
		Persistence.save();
		JOptionPane.showMessageDialog(null, "Patient has been updated");
	}

	/**
	 * @param info the info to set
	 */
	public void setInfo(PatientInformation info) {
		this.info = info;
	}
}
